//package org.mybatis.generator.api.plus;
//
//import org.mybatis.generator.api.IntrospectedColumn;
//import org.mybatis.generator.api.IntrospectedTable;
//import org.mybatis.generator.api.dom.java.TopLevelClass;
//
//import java.io.*;
//import java.util.Iterator;
//import java.util.List;
//
///**
// * @author wangfupeng
// */
//public class MybatisUtilCustomService {
//
//    public static void writeCustomService(String basePackageName, String aspectPackageName, String targetProject, TopLevelClass topLevelClass, IntrospectedTable introspectedTable, String tableName, String servicePackage) {
//        File file = null;
//        OutputStream fileOutputStream = null;
//        BufferedWriter bufferedWriter = null;
//        try {
//            String packageNameFolder = servicePackage.replaceAll("\\.", "/");
//            String[] packageNameFolders = packageNameFolder.split("/");
//            String packageNameFolderCustom = "";
//            String servicePackageCustom = "";
//            for (int i = 0; i < packageNameFolders.length - 1; i++) {
//                packageNameFolderCustom += packageNameFolders[i] + "/";
//                servicePackageCustom += packageNameFolders[i] + ".";
//            }
//            targetProject = targetProject.replaceAll("\\./", "");
//            File folder = new File(targetProject + "/" + packageNameFolderCustom + "/common/custom");
//            folder.mkdirs();
//            file = new File(targetProject + "/" + packageNameFolderCustom + "/common/custom/Custom" + tableName + "Service.java");
//            //如果文件不存在，则创建文件，如果已存在，则覆盖
//            //如果文件不存在，则创建文件，如果已存在，则覆盖
//            if (!file.exists()) {
//                file.createNewFile();
//                fileOutputStream = new FileOutputStream(file);
//                bufferedWriter = new BufferedWriter(new OutputStreamWriter(fileOutputStream, "utf-8"));
//                bufferedWriter.write("package " + servicePackageCustom + "custom;\n");
//                bufferedWriter.write("" +
//                        "\n" +
//                        "import java.util.List;\n" +
//                        "import com.gitee.fufu669.aspect.MockExecuteLater;\n" +
//                        "import org.springframework.beans.factory.annotation.Autowired;\n" +
//                        "import org.springframework.stereotype.Service;\n" +
//                        "import org.springframework.context.annotation.Lazy;\n" +
//                        "import " + basePackageName + ".bean.model."+introspectedTable.getFullyQualifiedTable().getDomainObjectName()+";\n" +
//                        "import " + basePackageName + ".bean.model." + introspectedTable.getFullyQualifiedTable().getDomainObjectName() + "Example;\n" +
//                        "\n" +
//                        "/*自定义"+introspectedTable.getRemarks()+"服务*/\n"+
//                        "@Lazy\n" +
//                        "@Service\n" +
//                        "public class Custom" + tableName + "Service {\n" +
//                        "    \n");
//
//                bufferedWriter.write("" +
//                        "    /*自定义创建"+introspectedTable.getRemarks()+"*/\n"+
//                        "    public void customCreate(" + introspectedTable.getFullyQualifiedTable().getDomainObjectName() + " " + MybatisUtilCommon.toLowerCaseAtFirstCharacter(introspectedTable.getFullyQualifiedTable().getDomainObjectName()) + "){\n" +
//                        "    }\n" +
//                        "\n" +
//                        "    /*自定义更改"+introspectedTable.getRemarks()+"*/\n"+
//                        "    public void customUpdate(" + introspectedTable.getFullyQualifiedTable().getDomainObjectName() + " " + MybatisUtilCommon.toLowerCaseAtFirstCharacter(introspectedTable.getFullyQualifiedTable().getDomainObjectName()) + "){\n" +
//                        "    }\n" +
//                        "\n" +
//                        "    /*自定义按关键字更改"+introspectedTable.getRemarks()+"*/\n"+
//                        "    public void customUpdateByPrimaryKeySelective(" + introspectedTable.getFullyQualifiedTable().getDomainObjectName() + " " + MybatisUtilCommon.toLowerCaseAtFirstCharacter(introspectedTable.getFullyQualifiedTable().getDomainObjectName()) + "){\n" +
//                        "    }\n" +
//                        "\n" +
//                        "    /*自定义按条件更改"+introspectedTable.getRemarks()+"*/\n"+
//                        "    public void customUpdateByExample(" + introspectedTable.getFullyQualifiedTable().getDomainObjectName() + " " + MybatisUtilCommon.toLowerCaseAtFirstCharacter(introspectedTable.getFullyQualifiedTable().getDomainObjectName()) + ",\n" +
//                        "        "+ introspectedTable.getFullyQualifiedTable().getDomainObjectName() + "Example "+ MybatisUtilCommon.toLowerCaseAtFirstCharacter(introspectedTable.getFullyQualifiedTable().getDomainObjectName()) + "Example\n" +
//                        "    ){\n" +
//                        "    }\n" +
//                        "\n" +
//                        "    /*自定义按条件，部分更改"+introspectedTable.getRemarks()+"*/\n"+
//                        "    public void customUpdateByExampleSelective(" + introspectedTable.getFullyQualifiedTable().getDomainObjectName() + " " + MybatisUtilCommon.toLowerCaseAtFirstCharacter(introspectedTable.getFullyQualifiedTable().getDomainObjectName()) + ",\n" +
//                        "        " + introspectedTable.getFullyQualifiedTable().getDomainObjectName() + "Example " + MybatisUtilCommon.toLowerCaseAtFirstCharacter(introspectedTable.getFullyQualifiedTable().getDomainObjectName()) + "Example\n" +
//                        "    ){\n" +
//                        "    }\n" +
//                        "\n" +
//                        "    /*自定义更改删除实例*/\n"+
//                        "    public void customDelete(" + introspectedTable.getFullyQualifiedTable().getDomainObjectName() + " " + MybatisUtilCommon.toLowerCaseAtFirstCharacter(introspectedTable.getFullyQualifiedTable().getDomainObjectName()) + "){\n" +
//                        "    }\n" +
//                        "\n" +
//                        "    /*自定义按条件更改删除实例*/\n"+
//                        "    public void customDeleteByExample(\n" +
//                        "        " + introspectedTable.getFullyQualifiedTable().getDomainObjectName() + "Example " + MybatisUtilCommon.toLowerCaseAtFirstCharacter(introspectedTable.getFullyQualifiedTable().getDomainObjectName()) + "Example\n" +
//                        "    ){\n" +
//                        "    }\n" +
//                        "\n" +
//                        "    /*自定义按关键字更改删除实例*/\n"+
//                        "    public void customDeleteByPrimaryKey(\n" +
//                        "        " + MybatisUtilCommon.getParameterTypeAndValueForPrimaryKeyColumns(introspectedTable) +
//                        "    ){\n" +
//                        "    }\n" +
//                        "\n" +
//                        "    /*自定义脱敏实例*/\n"+
//                        "    public void customSetWithoutSensitive(\n" +
//                        "        " + introspectedTable.getFullyQualifiedTable().getDomainObjectName() + " " + MybatisUtilCommon.toLowerCaseAtFirstCharacter(introspectedTable.getFullyQualifiedTable().getDomainObjectName()) +
//                        "    ){\n" +
//                        "    }\n" +
//                        "\n" +
//                        ""
//                );
//                /*List<IntrospectedColumn> introspectedColumns = introspectedTable.getPrimaryKeyColumns();*/
//                bufferedWriter.write("}\n");
//            }
//            System.out.println("write to file success : " + file.getPath());
//        } catch (Exception e) {
//            e.printStackTrace();
//        } finally {
//            MybatisUtilCommon.closeBufferWriterAndFileOutputStream(fileOutputStream, bufferedWriter);
//        }
//    }
//
//}
